{*******************************************************************************
* The contents of this file are used with permission, subject to the Mozilla   *
* Public License Version 1.1 (the "License"); you may not use this file except *
* in compliance with the License. You may obtain a copy of the License at      *
* http://www.mozilla.org/MPL/                                                  *
*                                                                              *
* Software distributed under the License is distributed on an "AS IS" basis,   *
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for *
* the specific language governing rights and limitations under the License.    *
*                                                                              *
* The Original Code is distributed as part of the "mediate" product and is     *
* Copyright (C) @home media limited. All Rights Reserved.                      *
*                                                                              *
* Email: support@athomemedia.co.uk                                             *
* Web:   http://www.athomemedia.co.uk                                          *
*******************************************************************************}

unit KeyBindingForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls;

type
  TfrmKeyBindings = class(TForm)
    btClose: TButton;
    lbDescription: TLabel;
    lvKeyBinding: TListView;
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
    FBinding: String;
  public
    { Public declarations }
    property BindingName: String read FBinding write FBinding;
  end;


implementation

{$R *.dfm}

uses ApplicationManager, ActionManager;

procedure TfrmKeyBindings.FormShow(Sender: TObject);
var
  Profile: TAHMKeyProfile;
  Binding: TAHMKeyBinding;
  i: Integer;
begin
  // Retrieve keybinding settings from action manager
  with ApplicationManagerInstance.ActionManager do
    Profile := KeyProfiles.GetKeyProfile(FBinding);

  // Populate description for keybinding
  if Assigned(Profile) then lbDescription.Caption := Profile.DisplayText
                       else lbDescription.Caption := '';

  // Populate list of key mappings
  if Assigned(Profile) then
  begin
    lvKeyBinding.Items.BeginUpdate;
    try
      for i := 0 to Pred(Profile.Count) do
        with lvKeyBinding.Items.Add do
        begin
          Binding := Profile.Binding[i];
          Caption := Binding.Name;
          SubItems.Add(Binding.DisplayText);
          SubItems.Add(IntToStr(Binding.KeyCode));
        end;
    finally
      lvKeyBinding.Items.EndUpdate;
    end;
  end;
end;

end.
